#ifndef KF_MEMORY_BLOCK_HEADER
#define KF_MEMORY_BLOCK_HEADER

#include "kf_types.h"

#include <ostream>

// to do: add search to memBlock

namespace kf
{
   class KF_API MemBlock
   {
   public:
      MemBlock();
      MemBlock(byte *start, dword length);
      ~MemBlock();
      void set_range(byte *start, dword length);
      void seek(dword offset, bool relative = false);
      MemBlock &operator+=(dword offset);
      MemBlock &operator-=(dword offset);
      MemBlock &operator++();
      MemBlock &operator--();
      bool operator==(const MemBlock &rhs);
      MemBlock &operator=(const MemBlock &rhs);
      byte *begin() const;
      byte *end() const;
      byte *current() const;
      dword size() const;
      dword  get_dword();
      sdword get_sdword();
      word   get_word();
      sword  get_sword();
      byte   get_byte();
      sbyte  get_sbyte();
      float  get_float();
      double get_double();
      void get_block(byte *destination, dword length);
      std::string get_string(dword length=0);
      void set_dword(dword value);
      void set_sdword(sdword value);
      void set_word(word value);
      void set_sword(sword value);
      void set_byte(byte value);
      void set_sbyte(sbyte value);
      void set_float(float value);
      void set_double(double value);
      void set_block(byte *source, dword length);
      void set_string(const std::string &value, bool include_terminator = true, dword length = 0, bool pad = false);

   /*
      MemBlock &operator<<(dword value);
      MemBlock &operator<<(sdword value);
      MemBlock &operator<<(word value);
      MemBlock &operator<<(sword value);
      MemBlock &operator<<(byte value);
      MemBlock &operator<<(sbyte value);
      MemBlock &operator<<(float value);
      MemBlock &operator<<(double value);
      MemBlock &operator<<(const std::string &value);
   */
      
   protected:
      byte *m_begin;
      byte *m_end;
      byte *m_current;
   };

   KF_API std::ostream &operator<<(std::ostream &os, const MemBlock &src);
}

#endif
